package org.edu.modules.center.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.map.HashedMap;
import org.edu.modules.center.Bo.VeTeachWeightsBo;
import org.edu.modules.center.dto.TeachStudentScoreDto;
import org.edu.modules.center.entity.VeTeachStudentScore;
import org.edu.modules.center.mapper.TeachStudentScoreMapper;
import org.edu.modules.center.service.ITeachStudentScoreService;
import org.edu.modules.center.service.IVeStudyProgressService;
import org.edu.modules.exam.service.IVeExamRecordService;
import org.edu.modules.opencourse.service.IVeKfcOpencourseService;
import org.edu.modules.weights.service.IVeTeachWeightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeachStudentScoreServiceImpl
        extends ServiceImpl<TeachStudentScoreMapper, VeTeachStudentScore>
        implements ITeachStudentScoreService
{
    @Autowired
    private IVeExamRecordService veExamRecordService;
    @Autowired
    private IVeTeachWeightsService veTeachWeightsService;
    @Autowired
    private IVeKfcOpencourseService veKfcOpencourseService;
    @Autowired
    private IVeStudyProgressService veStudyProgressService;

    public IPage<Map<String, Object>> scorePageMaps(Page<Map<String, Object>> page, QueryWrapper<VeTeachStudentScore> queryWrapper)
    {
        return ((TeachStudentScoreMapper)getBaseMapper()).scorePageMaps(page, queryWrapper);
    }

    public TeachStudentScoreDto queryScore(String tcid, String studentid)
    {
        Map<String, Object> params = new HashedMap();
        params.put("studentid", studentid);
        params.put("tcid", tcid);
        TeachStudentScoreDto teachStudentScoreDto = new TeachStudentScoreDto();
        List<VeTeachWeightsBo> veTeachWeightsBo = this.veTeachWeightsService.selectWeight(params);
        for (VeTeachWeightsBo v : veTeachWeightsBo)
        {
            if (v.getName().equals("学习时长"))
            {
                Integer studyTime = this.veStudyProgressService.selectStudyTime(params);
                Integer classHour = this.veKfcOpencourseService.selectClassHour(params);
                v.setClassHour(classHour);
                v.setStudyTime(studyTime);
            }
            if (v.getName().equals("期中考试"))
            {
                Integer midtermScore = this.veExamRecordService.midtermScore(params);
                v.setMidtermScore(midtermScore);
            }
            if (v.getName().equals("期末考试"))
            {
                Integer finalScore = this.veExamRecordService.selectFinalSource(params);
                v.setFinalScore(finalScore);
            }
            teachStudentScoreDto.setWeightList(veTeachWeightsBo);
        }
        return teachStudentScoreDto;
    }
}
